/*
 * Copyright (c) 2013 WDCY Information Technology Co. Ltd
 * www.wdcy.cc
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * WDCY Information Technology Co. Ltd ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with WDCY Information Technology Co. Ltd.
 */
package com.andaily.zhishifenzi.domain.commons;

import com.andaily.zhishifenzi.domain.album.Album;

/**
 * 14-3-8 下午8:16
 *
 * @author Shengzhao Li
 */
public class Photo extends GeckoFile {

    //图片完整的URL,如: http://sss.sdd/sdo.jpg
    private String url;

    private String description;
    //是否为 首页显示的图片
    private boolean headPhoto;

    private Album album;

    public Photo() {
    }

    public Photo(String name, byte[] data) {
        super(name, data);
    }

    public void saveOrUpdate() {
        if (this.data != null) {
            this.path = fileWarehouse.write(this.data);
        }
        if (isNewly()) {
            commonsRepository.savePhoto(this);
        } else {
            commonsRepository.updatePhoto(this);
        }
    }

    public String description() {
        return description;
    }

    public Photo description(String description) {
        this.description = description;
        return this;
    }

    public boolean headPhoto() {
        return headPhoto;
    }

    public Photo headPhoto(boolean headPhoto) {
        this.headPhoto = headPhoto;
        return this;
    }

    public String url() {
        return url;
    }

    public Photo url(String url) {
        this.url = url;
        return this;
    }

    public boolean isPhoto() {
        return true;
    }

    public Album album() {
        return album;
    }

    public Photo album(Album album) {
        this.album = album;
        return this;
    }

    public String remove() {
        this.delete();
        return album.guid();
    }
}
